Skip to content

fix: parse link (a tag) in post messages - #144

Merged
lishuceo merged 4 commits into
mainfrom
fix/post-link-parsing
Mar 12, 2026
Merged

fix: parse link (a tag) in post messages#144
lishuceo merged 4 commits into
mainfrom
fix/post-link-parsing

Conversation

@lishuceo

Copy link
Copy Markdown
Owner

Summary

  • Post 消息(富文本)中的链接 (a 标签) 未被解析,导致仅含链接的 post 被当作空内容跳过
  • 影响三个解析位置:message-parser.tsclient.ts (fetchRecentMessages)event-handler.ts (parseMessage)
  • 直接后果:用户在话题中回复链接并 @bot 时,bot 看不到话题开头的链接内容

Root Cause

Post 类型消息的解析仅提取 tag === 'text' 元素,忽略了 tag === 'a'(链接标签)。当 post 仅包含链接时,解析结果为空字符串,被 empty_content 规则跳过。

Fix

在三个位置的 post 解析循环中增加 a 标签处理,提取 texthref 并格式化为 [text](href)

Test plan

  • 新增 4 个测试用例覆盖:纯链接 post、混合文本+链接、仅 href 无 text、仅 text 无 href
  • 全量测试通过(20/20 merge-forward tests)

🤖 Generated with Claude Code

lishuceo and others added 2 commits March 12, 2026 12:16
Post messages containing only links were parsed as empty because the
parser only extracted 'text' tag elements, ignoring 'a' (link) tags.
This caused rootId injection and fetchRecentMessages to skip link-only
posts, making the bot unable to see links shared in thread topics.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@claude

claude Bot commented Mar 12, 2026

Copy link
Copy Markdown

Claude finished @lishuceo's task in 59s —— View job


PR Review: fix: parse link (a tag) in post messages

  • Check for previous review comments
  • Read changed files and review
  • Post review summary

Verdict: ✅ LGTM — No issues found

The fix is clean and consistent across all three parsing locations:

  1. message-parser.ts:36-40formatMergeForwardSubMessage now handles a tags
  2. client.ts:567-571fetchRecentMessages post parsing now handles a tags
  3. event-handler.ts:2233-2236parseMessage post parsing now handles a tags

All three use the same formatting logic: [text](href) when both present, falling back to href or text alone. The edge cases (empty text, empty href) are handled correctly.

Minor style note (not blocking): event-handler.ts uses || '' while the other two use ?? '' for the fallback. Both work identically here since element.text/element.href will only be undefined or a string (never 0 or other falsy values), so this is purely cosmetic.

Tests: 4 new test cases cover the key scenarios (pure link, mixed text+link, href-only, text-only). Good coverage.

lishuceo and others added 2 commits March 12, 2026 12:38
Add support for all Feishu post rich text element tags (referencing
OpenClaw's implementation): at, img, media, emotion, code_block, md, hr.
Previously only text and a were handled, causing content loss.

Also add explicit message type placeholders for media, interactive,
share_chat, share_user, and system message types.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Cover at, img, media, emotion, code_block, md, hr post tags and
media, interactive, share_chat, share_user, system message types.
35 tests total, all passing.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@claude

claude Bot commented Mar 12, 2026

Copy link
Copy Markdown

Claude finished @lishuceo's task in 1m 15s —— View job


PR Review: fix: parse link (a tag) in post messages

  • Check for previous review comments
  • Read changed files and review
  • Post review summary

Verdict: ✅ LGTM — No blocking issues

The PR expanded beyond the original a tag fix to handle all 9 post element tags (text, a, at, img, media, emotion, code_block, md, hr) and added message type placeholders. The logic is correct and well-tested.

Observations (non-blocking):

  1. Code duplication across 3 files — The post element parsing logic is now copy-pasted identically in message-parser.ts:34-57, client.ts:565-588, and event-handler.ts:2220-2253. This is a pre-existing pattern (not introduced by this PR), but with 9 tag types it's becoming substantial. A shared helper function would reduce the maintenance surface. Not blocking for this PR since the scope is a bug fix.

  2. || '' vs ?? '' inconsistencyevent-handler.ts uses || '' while message-parser.ts and client.ts use ?? ''. Both are functionally equivalent here (string values are never 0 or false), so this is purely cosmetic. Already noted in the previous review.

  3. event-handler.ts has richer img handling — It collects imageKeys for download rather than emitting [图片] placeholder, and its at handling filters out bot mentions. These are intentional contextual differences, not inconsistencies.

Tests: 20+ test cases covering all element tags, edge cases (empty text/href, mixed content), and message type placeholders. Good coverage.

@lishuceo
lishuceo merged commit 25db887 into main Mar 12, 2026
4 checks passed
@lishuceo
lishuceo deleted the fix/post-link-parsing branch March 12, 2026 05:22
lishuceo added a commit that referenced this pull request Apr 8, 2026
* fix: parse link (a tag) in post messages to prevent empty_content skip

Post messages containing only links were parsed as empty because the
parser only extracted 'text' tag elements, ignoring 'a' (link) tags.
This caused rootId injection and fetchRecentMessages to skip link-only
posts, making the bot unable to see links shared in thread topics.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* test: add tests for post messages with link (a tag) elements

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat: handle all 9 post element tags and additional message types

Add support for all Feishu post rich text element tags (referencing
OpenClaw's implementation): at, img, media, emotion, code_block, md, hr.
Previously only text and a were handled, causing content loss.

Also add explicit message type placeholders for media, interactive,
share_chat, share_user, and system message types.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* test: add tests for all post element tags and message type placeholders

Cover at, img, media, emotion, code_block, md, hr post tags and
media, interactive, share_chat, share_user, system message types.
35 tests total, all passing.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant